<div class="pageContent">
	<div class="panelBar panelBar_single">
		<ul class="toolBar">

			<li class="line">line</li>
			<li><a class="edit" href="#" onclick="return dsAttrBind_<?cs var:config.view_id ?>();"><i class='icon-lock icon-large'></i>监控点绑定</a></li>
			<li class="line">line</li>
			<li><a class="edit" href="#" onclick="return dsMachineBind_<?cs var:config.view_id ?>();"><i class='icon-server icon-large'></i>机器绑定</a></li>
			<li class="line">line</li>
			<li>指定日期：<input type="text" class="date" size="10" readonly="true" id="ds_date_<?cs var:config.view_id ?>" value="<?cs var:config.cust_date ?>" onblur="setTimeout(dsOnCustDateChange_<?cs var:config.view_id ?>, 600);" minDate="2014-01-01" maxDate="2088-12-31" /></li>

			<li class="line">line</li>
			<li><a class="add" href="#" onclick="return dsAttrShow_<?cs var:config.view_id ?>(2);"><i class='icon-bar-chart icon-large'></i>日图</a></li>

			<li class="line">line</li>
			<li><a class="add" href="#" onclick="return dsAttrShow_<?cs var:config.view_id ?>(1);"><i class='icon-area-chart icon-large'></i>日同比图</a></li>

			<li class="line">line</li>
			<li><a class="add" href="#" onclick="return dsAttrShow_<?cs var:config.view_id ?>(3);"><i class='icon-area-chart icon-large'></i>周图</a></li>

			<li class="line">line</li>
			<li style='line-height:34px'>
				<input type="checkbox" checked id="ds_check_show_<?cs var:config.view_id ?>" onclick="return dsCheckShow_<?cs var:config.view_id ?>();"/>
				<label class='for' for='ds_check_show_<?cs var:config.view_id ?>'>仅绘制有上报的图表</label>
			</li>
            <li style='line-height:34px'>
                <input type="checkbox" checked id="ds_not_show_zero_<?cs var:config.view_id ?>" onclick="return dsCheckShowZero_<?cs var:config.view_id ?>();"/>
                <label class='for' for='ds_not_show_zero_<?cs var:config.view_id ?>'>图表不显示数据为0的点</label>
            </li>
			<li style="display:none"><a id="ds_href_<?cs var:config.view_id ?>" href="#" target="navTab" rel="showview_<?cs var:config.view_id ?>" fresh="false"></a></li>

			<li class="line">line</li>
			<li style='float:right;margin-right:20px'><a class="add" href="#" onclick="return dsLeftMenuShow_<?cs var:config.view_id ?>();"><i class='icon-large' id='navi-show-icon_<?cs var:config.view_id ?>'></i>图表导航菜单</a></li>
		</ul>
	</div>

	<div> 
		<div id='dsLeftMenu_<?cs var:config.view_id ?>' layoutH="28" class="chartLeftMenu chart_navi">
            <div class="accordion" style='display:none'> 
            	<div class="accordionHeader attr_use_global_plug">
            		<h2><i class="icon-plug icon-large "></i><span class='navi_chart_text'>全局插件</span><i class="icon icon-chevron-up"></i></h2>
            	</div>
            	<div class="accordionContent attr_use_global_plug navi_attr_type_sub">
            		<ul class="tree"></ul>
            	</div>
 
            	<div class="accordionHeader attr_use_cust">
            		<h2><i class="icon-screenshot icon-large "></i><span class='navi_chart_text'>自定义监控点</span><i class="icon icon-chevron-up"></i></h2>
            	</div>
            	<div class="accordionContent attr_use_cust navi_attr_type_sub">
            		<ul class="tree"></ul>
            	</div>
           </div>
		</div> 
		<div layoutH="28" id="ds_ct_attr_show_list_<?cs var:config.view_id ?>" class="unitBox xrk_chart_container"> 
		</div>
	</div>
</div>

<script language="javascript" type="text/javascript">

// 以下两变量在别处有引用，请勿删除
var ds_view_name_<?cs var:config.view_id ?> = "<?cs var:config.view_name ?>";

var ds_attr_show_get_last_seq_<?cs var:config.view_id ?> = <?cs var:config.last_seq ?>;
var ds_attr_list_arry_<?cs var:config.view_id ?> = new Array();
var ds_attr_list_<?cs var:config.view_id ?> = <?cs var:config.view_attr_list ?>;
var ds_attr_show_index_cur_<?cs var:config.view_id ?>;
var ds_attr_show_get_auto_<?cs var:config.view_id ?> = null;
var ds_attr_show_type_<?cs var:config.view_id ?> = <?cs var:config.show_type ?>;
var ds_cust_date_save_<?cs var:config.view_id ?> = '<?cs var:config.cust_date ?>';
var ds_attr_show_process_<?cs var:config.view_id ?> = false;
var ds_attr_show_reqstart_timestamp_<?cs var:config.view_id ?> = new Date().getTime();
var ds_chart_ok_<?cs var:config.view_id ?> = false;
var ds_navi_menu_ok_<?cs var:config.view_id ?> = false;

// 视图绑定监控点对话框
function dsAttrBind_<?cs var:config.view_id ?>()
{
	var view_id = "<?cs var:config.view_id ?>";
	var url = "<?cs var:config.cgipath ?>mt_slog_showview?action=bind_attr";
	url += "&view_id=" + view_id;
	var dlg = "ds_dlg_bind_attr_" + view_id;

	var op = {"mask":false,"maxable":false,"height":480,"width":780,"resizable":false}; 
	$.pdialog.open(url, dlg, "绑定监控点", op); 
}

// 视图绑定机器对话框
function dsMachineBind_<?cs var:config.view_id ?>()
{
	var view_id = "<?cs var:config.view_id ?>";
	var url = "<?cs var:config.cgipath ?>mt_slog_showview?action=bind_machine";
	url += "&view_id=" + view_id;
	var dlg = "ds_dlg_bind_machine_" + view_id;

	var op = {"mask":true,"maxable":false,"height":460,"width":520,"resizable":false}; 
	$.pdialog.open(url, dlg, "绑定服务器", op); 
}

function dsOnCustDateChange_<?cs var:config.view_id ?>()
{
	var dt = $("#ds_date_<?cs var:config.view_id ?>").val();
	if(dt != ds_cust_date_save_<?cs var:config.view_id ?>)
	{
		return dsAttrShow_<?cs var:config.view_id ?>(ds_attr_show_type_<?cs var:config.view_id ?>);
	}
}

function dsLeftMenuShow_<?cs var:config.view_id ?>()
{
	if($('#dsLeftMenu_<?cs var:config.view_id ?>').css('display') == 'none')
	{
        $('#navi-show-icon_<?cs var:config.view_id ?>').removeClass('icon-double-angle-left').addClass('icon-double-angle-right');;
		$('#dsLeftMenu_<?cs var:config.view_id ?>').show();
		window.localStorage.setItem('dsLeftMenu_<?cs var:config.view_id ?>_hide', '0');
		dmtRedrawCharts('<?cs var:config.view_id ?>', 'view', true);
	}
	else
	{
        $('#navi-show-icon_<?cs var:config.view_id ?>').addClass('icon-double-angle-left').removeClass('icon-double-angle-right');;
		$('#dsLeftMenu_<?cs var:config.view_id ?>').hide();
		window.localStorage.setItem('dsLeftMenu_<?cs var:config.view_id ?>_hide', '1');
		dmtRedrawCharts('<?cs var:config.view_id ?>', 'view', false);
	}
}

function dsSetNaviMenuInfo_<?cs var:config.view_id ?>(js)
{
    var ary_attr_types = dmtGetAttrTypeList(ds_attr_list_<?cs var:config.view_id ?>);

    // 生成私有监控点类型信息
    dmtSetChartNavigatioInfo(
        ary_attr_types, js.user_self_cust, 'dsLeftMenu_<?cs var:config.view_id ?> .attr_use_cust');
    
    // 生成全局插件监控点类型信息
    dmtSetChartNavigatioInfo(
        ary_attr_types, js.global_plug, 'dsLeftMenu_<?cs var:config.view_id ?> .attr_use_global_plug');

    var listattr = ds_attr_list_<?cs var:config.view_id ?>.list;
    for(var j=0; j < ds_attr_list_<?cs var:config.view_id ?>.count && j < listattr.length; j++) 
    {
        var list = '';
        var attr_show_id = "attr_" + listattr[j].id + "_<?cs var:config.view_id ?>view";
        list += "<li>";
        list += "<a onclick=\"dmtJumpToAttrPic('";
        list += attr_show_id + "', '#ds_ct_attr_show_list_<?cs var:config.view_id ?>', ";
        list += dsClickViewAttr_<?cs var:config.view_id ?> + ")\" href='#' ctid='" + attr_show_id + "'>";
        list += listattr[j].name;
        list += "</a>";
        list += "</li>";
        $('#dsLeftMenu_<?cs var:config.view_id ?> ul[attr_type="' + listattr[j].attr_type + '"').append(list);
    }
    $('#dsLeftMenu_<?cs var:config.view_id ?>').initUI();
    $('#dsLeftMenu_<?cs var:config.view_id ?> .accordion').show();
    if(ds_chart_ok_<?cs var:config.view_id ?>)
        dmtAddNoDataTextForView(
            'dsLeftMenu_<?cs var:config.view_id ?>', 'ds_ct_attr_show_list_<?cs var:config.view_id ?>');
    ds_navi_menu_ok_<?cs var:config.view_id ?> = true;
}

function dsGetAttrTypeInfo_<?cs var:config.view_id ?>()
{
    var rurl = '<?cs var:config.cgipath?>mt_slog_attr?action=get_attr_type_for_chart';
    $.ajax({
        type: "get",
        url: rurl,
        success: function(js) {
            if(dmtFirstDealAjaxResponse(js))
                return;
            if(typeof js.ret == 'undefined' || js.ret != 0) {
                alertMsg.warn("监控点类型信息获取失败，图表导航功能暂不能使用");
                return;
            }
            g_attr_type_list = js;
            dsSetNaviMenuInfo_<?cs var:config.view_id ?>(js);
        },
        dataType: 'json', 
        global: false
    });
}

function dsClickViewAttr_<?cs var:config.view_id ?>(show_id)
{
	// 寻找该图表的数组索引
	var arrStr = show_id.split('_');
	var i = 0;
	for(; i < ds_attr_list_arry_<?cs var:config.view_id ?>.length; i++)
	{
		if(arrStr[1] == ds_attr_list_arry_<?cs var:config.view_id ?>[i])
			break;
	}

	// 没找到非法 attr
	if(i >= ds_attr_list_arry_<?cs var:config.view_id ?>.length)
		return false;

	// 已获取到的 attr, 没有数据上报
	if(i < ds_attr_show_index_cur_<?cs var:config.view_id ?>)
		return false;

	// 正在获取中的 attr
	return true;
}

function dsAttrShow_<?cs var:config.view_id ?>(type)
{
	var dt = $("#ds_date_<?cs var:config.view_id ?>").val();
	if(dt != "")
		param = '&date=' + dt;
	else
		param = "&date=today" 

	var ck = $("#ds_check_show_<?cs var:config.view_id ?>").is(":checked");
	if(ck)
		param += '&show_rep=1';
	else
		param += '&show_rep=0';
	
    var ck = $("#ds_not_show_zero_<?cs var:config.view_id ?>").is(":checked");
	if(ck)
	    param += '&show_zero=0';
    else
        param += '&show_zero=1';

	param += '&_r=' + Math.random();
	param += '&view_id=' + '<?cs var:config.view_id ?>';
	param += '&type=' + type;
	param += '&view_name=' + '<?cs var:config.view_name ?>';

	var requrl = "<?cs var:config.cgipath ?>mt_slog_showview?action=list" + param;
	var idhref = "#ds_href_<?cs var:config.view_id ?>";
	$(idhref).html(ds_view_name_<?cs var:config.view_id ?>);

	$(idhref).attr('href', requrl);
	$(idhref).click();
	return false;
}

function dsAttrShowDate2_<?cs var:config.view_id ?>(idx)
{
	var reqAttr = ds_attr_list_arry_<?cs var:config.view_id ?>.slice(
			idx, idx+<?cs var:config.per_count ?>);
	if(reqAttr.length <= 0)
	{
		if(ds_attr_show_process_<?cs var:config.view_id ?> || $('#my_background').css('display') != 'none') {
			setTimeout(function() { $("#my_background,#my_progressBar").hide(); }, 1000);
		}
		return;
	}

	var requrl = "<?cs var:config.cgipath?>mt_slog_showview";
	var reqpara = {};
	var ck = $("#ds_check_show_<?cs var:config.view_id ?>").is(":checked");
	if(ck)
		reqpara.show_rep = 1;
	else
		reqpara.show_rep = 0;
    var ck = $("#ds_not_show_zero_<?cs var:config.view_id ?>").is(":checked");
	if(ck)
		reqpara.show_zero = 0;
    else 
		reqpara.show_zero = 1;
	
	reqpara.view_id = <?cs var:config.view_id ?>;
	reqpara.attr_list = reqAttr.toString();
	reqpara.action = 'show_view_attr_cust';
	reqpara.last_seq = ds_attr_show_get_last_seq_<?cs var:config.view_id ?>;;
	reqpara.type = ds_attr_show_type_<?cs var:config.view_id ?>;
	if(ds_attr_show_get_auto_<?cs var:config.view_id ?> == 'auto')
		reqpara.global = false;
	else
		reqpara.global = true;

	var dt = $("#ds_date_<?cs var:config.view_id ?>").val();
	if(dt != "")
		reqpara.date = dt;
	else
		reqpara.date = 'today';
	reqpara._r = Math.random();
	if(!ds_attr_show_process_<?cs var:config.view_id ?>){
		if(new Date().getTime() > ds_attr_show_reqstart_timestamp_<?cs var:config.view_id ?>+300) {
			$('#my_progressBar font').text('图表加载中, 请稍等...');
			$("#my_background,#my_progressBar").show();
			ds_attr_show_process_<?cs var:config.view_id ?> = true;
		}
	}

	ds_attr_show_index_cur_<?cs var:config.view_id ?> = idx; 
	ajaxTodoPost(requrl, reqpara, function(json) {
		if(dmtFirstDealAjaxResponse(json))
			return;

		if(json.statusCode == DWZ.statusCode.success ||json.statusCode == DWZ.statusCode.ok)
		{
			if(ds_attr_show_get_last_seq_<?cs var:config.view_id ?> != json.last_req_seq)
				return;

			dmtShowAttrInfo(json.attr_list, json.attr_val_list, 
				'#ds_ct_attr_show_list_<?cs var:config.view_id ?>', 'view');

			// ajax 自动获取
			if(ds_attr_show_index_cur_<?cs var:config.view_id ?> + <?cs var:config.per_count ?>
				< ds_attr_list_arry_<?cs var:config.view_id ?>.length) 
			{
				ds_attr_show_get_auto_<?cs var:config.view_id ?> = 'auto';
				dsAttrShowDate2_<?cs var:config.view_id?>(
					ds_attr_show_index_cur_<?cs var:config.view_id ?> + <?cs var:config.per_count ?>);
			}
			else
			{
				// 获取完毕
				ds_attr_show_get_auto_<?cs var:config.view_id ?> = null;
				ds_attr_show_index_cur_<?cs var:config.view_id ?> = ds_attr_list_arry_<?cs var:config.view_id ?>.length;
				if(ds_navi_menu_ok_<?cs var:config.view_id ?>)
					dmtAddNoDataTextForView(
                        'dsLeftMenu_<?cs var:config.view_id ?>', 'ds_ct_attr_show_list_<?cs var:config.view_id ?>');
                ds_chart_ok_<?cs var:config.view_id ?> = true;
				if(ds_attr_show_process_<?cs var:config.view_id ?> || $('#my_background').css('display') != 'none') {
					setTimeout(function() { $("#my_background,#my_progressBar").hide(); }, 1000);
				}
			}
		}
		else if(json.msgid && alertMsg)
		{
			var msg = DWZ.msg(json.msgid);
			alertMsg.warn(msg);
		}
		else if(json.msg)
			alertMsg.warn(json.msg);
	});
}

$(document).ready(function(){
    var notShowZero = window.localStorage.getItem("local_ds_not_show_zero_<?cs var:config.view_id ?>");
	if(notShowZero === '1')
		$("#ds_not_show_zero_<?cs var:config.view_id ?>").prop('checked', true);
	else if(notShowZero === '0')
		$("#ds_not_show_zero_<?cs var:config.view_id ?>").prop('checked', false);

	$('#ds_ct_attr_show_list_<?cs var:config.view_id ?>').html('');
    dmtGetAttrIdList(ds_attr_list_<?cs var:config.view_id ?>, ds_attr_list_arry_<?cs var:config.view_id ?>);
	var hideLeft = window.localStorage.getItem("dsLeftMenu_<?cs var:config.view_id ?>_hide");
    if(hideLeft === '1') {
		$('#dsLeftMenu_<?cs var:config.view_id ?>').hide();
        $('#navi-show-icon_<?cs var:config.view_id ?>').addClass('icon-double-angle-left');
	    dmtSetRedrawChartsInfo('<?cs var:config.view_id ?>', 'view', false);
    }
    else if(hideLeft === '0') {
        $('#navi-show-icon_<?cs var:config.view_id ?>').addClass('icon-double-angle-right');
	    dmtSetRedrawChartsInfo('<?cs var:config.view_id ?>', 'view', true);
    }
    else {
        if(ds_attr_list_arry_<?cs var:config.view_id ?>.length <= 10) {
            $('#dsLeftMenu_<?cs var:config.view_id ?>').hide();
            $('#navi-show-icon_<?cs var:config.view_id ?>').addClass('icon-double-angle-left');
	        dmtSetRedrawChartsInfo('<?cs var:config.view_id ?>', 'view', false);
        }
        else {
            $('#navi-show-icon_<?cs var:config.view_id ?>').addClass('icon-double-angle-right');
	        dmtSetRedrawChartsInfo('<?cs var:config.view_id ?>', 'view', true);
        }
    }
	dmtSetChartSize();

    var ck = window.localStorage.getItem("cookie_ds_check_show_<?cs var:config.view_id ?>");
    if(ck === '1')
        $("#ds_check_show_<?cs var:config.view_id ?>").prop("checked", true);
    else if(ck === '0')
        $("#ds_check_show_<?cs var:config.view_id ?>").prop("checked", false);

    if(ds_attr_list_arry_<?cs var:config.view_id ?>.length > 0) {
        dsAttrShowDate2_<?cs var:config.view_id ?>(0);
        dsGetAttrTypeInfo_<?cs var:config.view_id ?>();
    }
    else {
        var nhtml = '<font color="red" style="font-size:16px;font-weight:bold;">视图尚未绑定监控点</font>';
        $('#ds_ct_attr_show_list_<?cs var:config.view_id ?>').css('padding-top', '20px').html(nhtml);
    } 
});

function dsCheckShowZero_<?cs var:config.view_id ?>()
{
    var ckName = "local_ds_not_show_zero_<?cs var:config.view_id ?>";
    var ck = $("#ds_not_show_zero_<?cs var:config.view_id ?>").is(":checked");
    if(ck)
        window.localStorage.setItem(ckName, '1');
    else
        window.localStorage.setItem(ckName, '0');
    return dsAttrShow_<?cs var:config.view_id ?>(ds_attr_show_type_<?cs var:config.view_id ?>);
}

function dsCheckShow_<?cs var:config.view_id ?>()
{
	var ckName = "cookie_ds_check_show_<?cs var:config.view_id ?>";
	var ck = $("#ds_check_show_<?cs var:config.view_id ?>").is(":checked");
	if(ck)
		window.localStorage.setItem(ckName, '1');
	else
		window.localStorage.setItem(ckName, '0');
	return dsAttrShow_<?cs var:config.view_id ?>(ds_attr_show_type_<?cs var:config.view_id ?>);
}

</script>


